package com.zzyl.nursing.service.impl;

import java.util.List;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzyl.common.constant.HttpStatus;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.DateUtils;
import com.zzyl.nursing.dto.ElderQueryDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zzyl.nursing.mapper.ElderMapper;
import com.zzyl.nursing.domain.Elder;
import com.zzyl.nursing.service.IElderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Arrays;

/**
 * 老人信息Service业务层处理
 * 
 * @author zouguanghuan
 * @date 2025-10-21
 */
@Service
public class ElderServiceImpl extends ServiceImpl<ElderMapper, Elder> implements IElderService {
    @Autowired
    private ElderMapper elderMapper;

    /**
     * 查询老人信息
     * 
     * @param id 老人信息主键
     * @return 老人信息
     */
    @Override
    public Elder selectElderById(Long id) {
        return getById(id);
    }

    /**
     * 查询老人信息列表
     * 
     * @param elder 老人信息
     * @return 老人信息
     */
    @Override
    public List<Elder> selectElderList(Elder elder) {
        return elderMapper.selectElderList(elder);
    }

    /**
     * 新增老人信息
     * 
     * @param elder 老人信息
     * @return 结果
     */
    @Override
    public int insertElder(Elder elder) {
        return save(elder) ? 1 : 0;
    }

    /**
     * 修改老人信息
     * 
     * @param elder 老人信息
     * @return 结果
     */
    @Override
    public int updateElder(Elder elder) {
        return updateById(elder) ? 1 : 0;
    }

    /**
     * 批量删除老人信息
     * 
     * @param ids 需要删除的老人信息主键
     * @return 结果
     */
    @Override
    public int deleteElderByIds(Long[] ids) {
        return removeByIds(Arrays.asList(ids)) ? 1 : 0;
    }

    /**
     * 删除老人信息信息
     * 
     * @param id 老人信息主键
     * @return 结果
     */
    @Override
    public int deleteElderById(Long id) {
        return removeById(id) ? 1 : 0;
    }

    @Override
    public TableDataInfo<Elder> pageQuery(ElderQueryDto dto){
        Page<Elder> pageInfo = Page.of(dto.getPageNum(),dto.getPageSize());
        lambdaQuery().like(StrUtil.isNotEmpty(dto.getName()),Elder::getName,dto.getName())
                .like(StrUtil.isNotEmpty(dto.getIdCardNo()),Elder::getIdCardNo,dto.getIdCardNo())
                .eq(Elder::getStatus,dto.getStatus())
                //指定查询的字段
                .select(Elder::getId,Elder::getName,Elder::getIdCardNo, Elder::getBedNumber)
                .page(pageInfo);

        //封装结果返回
        return new TableDataInfo<>(pageInfo.getTotal(), pageInfo.getRecords(), HttpStatus.SUCCESS, "查询成功");
    }
}
